var express = require('express');
var router = express.Router();
var httpget=require('../util/httpget');
var httpPost=require('../util/httpPost');
/* GET home page. */
router.get('/all', function(req, res, next) {
	httpget('http://localhost:8008/empSelect').then(function(data){
		if(data.status==200){
			res.render('emp_all', { data: data.data });
		}else{
			res.send("请求失败");
		}
		
	}); 
});
router.get('/insert_view',function (req,res,next){
	res.render('emp_insert.ejs');
});

router.post('/insert',function (req,res,next){
	httpPost('/insert_employee',req.body).then(function (data){
		if(data.status==200){
			res.redirect('all');
		}
	});
});

router.get('/delete',function (req,res,next){
	httpPost('/delete_employee',req.query).then(function (data){
		if(data.status==200){
			res.redirect('all');
		}
	});
});

router.get('/editEmp_view',function (req,res,next){
	httpPost('/query_employeeById',req.query).then(function (data){
		if(data.status==200){
			res.render('emp_edit.ejs',{ data: data.data[0] });
		}else{
			res.send("请求失败");
		}
	});
});

router.post('/edit',function (req,res,next){
	httpPost('/edit_employee',req.body).then(function (data){
		if(data.status==200){
			res.redirect('all');
		}
	});
});
module.exports = router;
